import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FindLUSlength {

    public static void main(String[] args) {
        String s = "aedsad";
        String s1 = "ahdhjd";
    }

    StringBuilder stringBuilder = new StringBuilder();
    List<String> list = new ArrayList<>();
    public int findLUSlength1(String a, String b) {
        if (a.length() != b.length()) return a.length() > b.length() ? a.length() : b.length();
        dfs(0, a);
        Collections.sort(list, (i, j) -> {
            return j.length() - i.length();
        });
        for (String s : list) {
            int p1 = 0;
            int p2 = 0;
            while (p1 < s.length() && p2 < b.length()) {
                if (s.charAt(p1) == b.charAt(p2)) ++p1;
                ++p2;
            }
            if (p1 != s.length()) return s.length();
        }
        return -1;
    }

    public void dfs(int i, String s) {
        if (i == s.length()) {
            if (!stringBuilder.toString().equals("")) list.add(stringBuilder.toString());
            return;
        }
        dfs(i + 1, s);
        stringBuilder.append(s.charAt(i));
        dfs(i + 1, s);
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
    }

    public int findLUSlength(String a, String b) {
        if (a.length() != b.length()) return a.length() > b.length() ? a.length() : b.length();
        if (a.equals(b)) {
            return -1;
        } else return a.length();
    }
}
